package com.guli.mall.serviceBase.config;
/*
 * @Author 罗俊
 * @date 2020/11/23 - 11:03 上午
 *
 */

import com.alibaba.druid.pool.DruidDataSource;
import com.zaxxer.hikari.HikariDataSource;
import io.seata.rm.datasource.DataSourceProxy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.util.StringUtils;

import javax.sql.DataSource;
@Slf4j
@ConditionalOnClass(DataSourceProxy.class)
public class SeataDataSourceWrapperConfig {


    //@Bean
    public DataSourceProxy createSeataProxyDataSource(DataSourceProperties properties/*, Class<? extends DataSource> type*/) {

        DruidDataSource hikariDataSource = properties.initializeDataSourceBuilder().type(DruidDataSource.class).build();

        log.info("正在将数据源包装为 Seata 代理数据源");

        return new DataSourceProxy(hikariDataSource);
    }

}
